﻿@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject IWorkContext workContext
@{
    const string panelId = "order-average-report-box";
    const string hidePanelAttributeName = "Reports.HideOrderAverageReportPanel";
    var hidePanel = genericAttributeService.GetAttribute<bool>(workContext.CurrentCustomer, hidePanelAttributeName);
}

<div class="box box-info @if(hidePanel){<text>collapsed-box</text>}" id="@panelId">
    <div class="box-header with-border">
        <h3 class="box-title">
            <i class="fa fa-money"></i>
            @T("Admin.SalesReport.Average")
        </h3>
        <div class="box-tools pull-right">
            <button class="btn btn-box-tool" data-widget="collapse">
                @if (hidePanel)
                {
                    <text><i class="fa fa-plus"></i></text>
                }
                else
                {
                    <text><i class="fa fa-minus"></i></text>
                }
            </button>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $('#@panelId').on('click', 'button[data-widget="collapse"]', function () {
                var collapsed = !$('#@panelId').hasClass('collapsed-box');
                saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hidePanelAttributeName', collapsed);
            });
        });
    </script>
    <div class="box-body" style="padding-bottom: 22px;">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "average-order-report-grid",
            UrlRead = new DataUrl("OrderAverageReportList", "Order", null),
            Length = int.MaxValue,
            Paging = false,
            Info = false,
            ColumnCollection = new List<ColumnProperty>
            {
                new ColumnProperty(nameof(OrderAverageReportModel.OrderStatus))
                {
                    Title = T("Admin.SalesReport.Average.OrderStatus").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumTodayOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumTodayOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumThisWeekOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumThisWeekOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumThisMonthOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumThisMonthOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumThisYearOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumThisYearOrders").Text
                },
                new ColumnProperty(nameof(OrderAverageReportModel.SumAllTimeOrders))
                {
                    Title = T("Admin.SalesReport.Average.SumAllTimeOrders").Text
                }
            }
        })
    </div>
</div>